<?php
class FloorController extends Yaf_Controller_Abstract{
	const NET_OK = 10;
	const NET_NOAUTH = 20;
	public function init(){
		Yaf_Loader::import('import.php');
	}
	/**
	 * 楼层首页
	 * @method indexAction
	 * @return [type]      [description]
	 * @author NewFuture
	 */
	public function indexAction(){
		$user = cookie::get('user');
		if(!$user){
			$this->redirect('/index/login/');
			return false;
		}
		$search['floorNo'] = $this->getRequest()->getPost('floor_num');
		$search['floorName'] = $this->getRequest()->getPost('floor');
		$search['page'] = $this->getRequest()->getQuery('page')?:1;
		$search['n'] = 2;
		$result = net::inst('autoBG')->floorSearch($search);
		//var_dump($result);
		if(isset($result->ret)&&$result->ret == self::NET_OK){
			$this->getView()->assign('result',$result);
			$this->getView()->assign('floorId',$result->list[0]);
		}else if(isset($result->ret)&&$result->ret == self::NET_NOAUTH){
			$this->getView()->assign('error',$result->msg);
		}
        $this->getView()->assign('floorNo',$search['floorNo']);
        $this->getView()->assign('floorName',$search['floorName']);
	}
	/**
	 * 楼层信息添加
	 * @method addFloorAction
	 * @return [type]      [description]
	 * @author NewFuture
	 */
	public function addFloorAction(){
		$user = cookie::get('user');
		if(!$user){
			$this->redirect('/index/login/');
		}
	}
	/**
	 * 楼层修改
	 * @method floorEditAction
	 * @return [type]      [description]
	 * @author NewFuture
	 */
	public function floorEditAction(){
		$user = cookie::get('user');
		if(!$user){
			$this->redirect('/index/login/');
		}
		$params['floorId'] = $_GET['param'];
		$result = net::inst('autoBG')->floorDetail($params);
		//var_dump($result);
		if(isset($result->ret)&&$result->ret == self::NET_OK){
			$this->getView()->assign('floorDetail',$result->list[0]);
		}else if(isset($result->ret)&&$result->ret == self::NET_NOAUTH){
			$this->getView()->assign('error',$result->msg);
		}
	}
	/**
	 * 楼层详情
	 * @method floorDetailAction
	 * @return [type]      [description]
	 * @author NewFuture
	 */
	public function floorDetailAction(){
		$params = $_GET;
		$result = net::inst('autoBG')->floorInfo($params);
		if(isset($result->ret)&&$result->ret == self::NET_OK){
			$this->getView()->assign('floorDetail',$result->list[0]);
		}else if(isset($result->ret)&&$result->ret == self::NET_NOAUTH){
			$this->getView()->assign('error',$result->msg);
		}else{
			$this->getView()->assign('error','服务器连接错误！');
		}
	}
	/**
	 * 路点列表
	 * @method addRoadAction
	 * @return [type]      [description]
	 * @author NewFuture
	 */
	public function addRoadAction(){
		$user = cookie::get('user');
		if(!$user){
			$this->redirect('/index/login/');
		}
		$params['floorId'] = $_GET['floorNo'];
		$params['page'] = $this->getRequest()->getQuery('page')?:1;
		$params['n'] = 100;
		$result = net::inst('autoBG')->magPointInit($params);
		if(isset($result->ret)&&$result->ret == self::NET_OK){
			$this->getView()->assign('roadDetail',$result->list);
			$this->getView()->assign('floorId',$params['floorId']);
		}else{
			$this->getView()->assign('error',$result->msg);
		}
	}
	/**
	 * 路点添加
	 * @method addRoadsAction
	 * @return [type]      [description]
	 * @author NewFuture
	 */
	public function addRoadsAction(){
		$user = cookie::get('user');
		if(!$user){
			$this->redirect('/index/login/');
		}
		$params = $_GET;
		if(!empty($params)){
			$this->getView()->assign('floorId',$params['floorId']);
		}else{
			$this->getView()->assign('error','参数错误！请重试！');
		}
	}
	/**
	 * 路点修改
	 * @method roadEditAction
	 * @return [type]      [description]
	 * @author NewFuture
	 */
	public function roadEditAction(){
		$user = cookie::get('user');
		if(!$user){
			$this->redirect('/index/login/');
		}
		$params = $_GET;
		$result = net::inst('autoBG')->magPointDetail($params);
		if(isset($result->ret)&&$result->ret == self::NET_OK){
			$this->getView()->assign('pointDetail',$result->list[0]);
		}else if(isset($result->ret)&&$result->ret == self::NET_NOAUTH){
			$this->getView()->assign('error',$result->msg);
		}else{
			$this->getView()->assign('error','服务器连接错误！');
		}
	}
	/**
	 * 路径设置
	 * @method setPathAction
	 * @return [type]      [description]
	 * @author NewFuture
	 */
	public function setPathAction(){
		$user = cookie::get('user');
		if(!$user){
			$this->redirect('/index/login/');
		}
		$params['floorId'] = $_GET['floorId'];
		$params['pointId'] = $_GET['pointId'];
		$result = net::inst('autoBG')->pathInit($params);
		//var_dump($result);
		if($result->ret == self::NET_OK){
			$this->getView()->assign('pathDetail',$result->list);
			$this->getView()->assign('coorCurrent',$_GET['coorCurrent']);
			$this->getView()->assign('pointId',$params['pointId']);
		}else{
			$this->getView()->assign('error',$result->msg);
		}
	}
}